package leetcode_day._2021._202106._0110;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/6/1 22:04
 * 你能在你最喜欢的那天吃到你最喜欢的糖果吗？
 * 算法：前缀和
 * 算出最晚/最早吃到糖的天数
 */
public class _01_1744 {

    public boolean[] canEat(int[] candiesCount, int[][] queries) {
        long[] pre = new long[candiesCount.length + 1];
        for (int i = 1; i <= candiesCount.length; i++) pre[i] = pre[i - 1] + candiesCount[i - 1];
        boolean[] ans = new boolean[queries.length];
        for (int i = 0; i < queries.length; i++) {
            int[] query = queries[i];
            int t = query[0], d = query[1] + 1, c = query[2];
            long min = pre[t] / c + 1, max = pre[t + 1];
            ans[i] = min <= d && d <= max;
        }
        return ans;
    }

}
